package com.niit.controller;

import com.niit.entity.Company;
import com.niit.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/company")
public class CompanyController {

    @Autowired
    private CompanyService companyService;

    @GetMapping("/index")
    public String company() {
        return "company";
    }

    @GetMapping("/list")
    public Page<Company> getCompanyList(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(required = false) String companyName) {
	    return companyService.getCompanyPage(page, size, companyName);
    }

    @PostMapping("/delete/{id}")
    public void deleteCompany(@PathVariable Integer id) {
        companyService.deleteCompany(id);
    }

    @PostMapping("/add")
    public Company addCompany(@RequestBody Company company) {
        return companyService.addCompany(company);
    }

    @PostMapping("/getAll")
    public List<Company> getAllCompany() {
        return companyService.getAllCompany();
    }

    @GetMapping("/getCompany/{id}")
    public Company getCompany(@PathVariable Integer id){
        return companyService.getCompanyById(id);
    }
}